﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Neuron.Esb;
using Neuron.Esb.Pipelines;
using Neuron.Pipelines;
using Neuron.Scripting;
using System.Runtime.Serialization;
using System.ComponentModel;
using System.Transactions;
using System.Windows.Forms;
using System.Drawing.Design;

namespace Neuron.Pipelines.CustomSamples
{
    [DisplayName("My Custom Pipeline Step")]
    [Description("This is a custom pipeline step.")]
    public class MyCustomPipelineStep : CustomPipelineStep
    {
        [DataMember]
        [Category("My Category")]
        [DisplayName("My Property")]
        [Description("My Property Description")]
        [Bindable(false)]
        public String MyProperty { get; set; }

        [DataMember]
        [Category("My Category")]
        [DisplayName("My Bindable Property")]
        [Description("My Bindable Property Description")]
        [Bindable(true)]
        public String MyBindableProperty { get; set; }

        String MyPrivateProperty { get; set; }

        int _myDefaultValueProperty = 3;
        [DataMember]
        [Category("My Category")]
        [DisplayName("My Default Value Property")]
        [Description("My Default Value Property Description")]
        [Bindable(false)]
        [DefaultValue(3)]
        public int MyDefaultValueProperty { get { return _myDefaultValueProperty; } set { _myDefaultValueProperty = value; } }

        [DataMember]
        [Category("My Category")]
        [DisplayName("My Type Converter Property")]
        [Description("My Type Converter Property Description")]
        [Bindable(false)]
        [TypeConverter(typeof(MyTypeConverterPropertyConverter))]
        public String MyTypeConverterProperty { get; set; }

        [Category("My Category")]
        [DisplayName("My Editor Property")]
        [Description("My Editor Property Description")]
        [Bindable(false)]
        [Editor(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
        public String MyEditorProperty { get; set; }

        protected override void OnExecute(PipelineContext<ESBMessage> context)
        {
            context.Instance.TraceInformation("MyCustomPipelineStep called. Value of MyProperty = " + MyProperty);
        }
    }

    public class MyTypeConverterPropertyConverter : StringConverter
    {
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            List<String> values = new List<string>();
            values.Add("My Value 1");
            values.Add("My Value 2");
            return new StandardValuesCollection(values.ToArray());
        }

        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return false;
        }                   
    }
}
